#pragma once

#include <map>
#include <boost/function.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <windows.h>




//参数一是timer的ID, 参数二是定时的时间,  返回值true表示timer将继续下去, false表示timer将结束
//bool OnTimer(UINT timerID, UINT elapse){return true;}
typedef boost::function<bool (UINT, UINT)> TimerCallback;


//对象析构会杀死定时器--如果定时器是活动的
//调用Start/ReStart会杀死已经存在的定时器
//此Timer类只能在主线程中使用!!
/*
举例:
bool OnTimer(UINT timerID, UINT elapse){
cout<<timerID<<" "<<elapse<<endl;
return true;
}

Timer t;
t.Start(1000, OnTimer);
cout<<t.GetTimerID()<<endl;
cout<<t.IsActive()<<endl;
t.Stop();
cout<<t.IsActive()<<endl;
*/
class Timer{
public:
	Timer() ;
	virtual ~Timer();
	UINT ReStart();
	UINT Start(UINT elapse, TimerCallback callback);
	void Stop();
	bool IsActive();
	UINT GetTimerID();
private:
	UINT timerID;
	UINT elapse_;
	TimerCallback callback_;

	static void  CALLBACK MyTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
};
